home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / jce.jar / javax / crypto / Mac.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-07-27  |  5.7 KB  |  313 lines

  1. package javax.crypto;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.security.InvalidAlgorithmParameterException;
  5. import java.security.InvalidKeyException;
  6. import java.security.Key;
  7. import java.security.NoSuchAlgorithmException;
  8. import java.security.NoSuchProviderException;
  9. import java.security.Provider;
  10. import java.security.ProviderException;
  11. import java.security.spec.AlgorithmParameterSpec;
  12. import java.util.Iterator;
  13. import java.util.List;
  14. import sun.security.jca.GetInstance;
  15. import sun.security.util.Debug;
  16.  
  17. public class Mac implements Cloneable {
  18.    // $FF: renamed from: a sun.security.util.Debug
  19.    private static final Debug field_0 = Debug.getInstance("jca", "Mac");
  20.    // $FF: renamed from: b java.security.Provider
  21.    private Provider field_1;
  22.    // $FF: renamed from: c javax.crypto.MacSpi
  23.    private MacSpi field_2;
  24.    // $FF: renamed from: d java.lang.String
  25.    private final String field_3;
  26.    // $FF: renamed from: e boolean
  27.    private boolean field_4 = false;
  28.    // $FF: renamed from: f java.security.Provider.Service
  29.    private Provider.Service field_5;
  30.    // $FF: renamed from: g java.util.Iterator
  31.    private Iterator field_6;
  32.    // $FF: renamed from: h java.lang.Object
  33.    private final Object field_7;
  34.    // $FF: renamed from: i int
  35.    private static int field_8 = 10;
  36.  
  37.    protected Mac(MacSpi var1, Provider var2, String var3) {
  38.       this.field_2 = var1;
  39.       this.field_1 = var2;
  40.       this.field_3 = var3;
  41.       this.field_6 = null;
  42.       this.field_7 = null;
  43.    }
  44.  
  45.    private Mac(Provider.Service var1, Iterator var2, String var3) {
  46.       this.field_5 = var1;
  47.       this.field_6 = var2;
  48.       this.field_3 = var3;
  49.       this.field_7 = new Object();
  50.    }
  51.  
  52.    public final String getAlgorithm() {
  53.       return this.field_3;
  54.    }
  55.  
  56.    public static final Mac getInstance(String var0) throws NoSuchAlgorithmException {
  57.       List var1 = GetInstance.getServices("Mac", var0);
  58.       Iterator var2 = var1.iterator();
  59.  
  60.       while(var2.hasNext()) {
  61.          Provider.Service var3 = (Provider.Service)var2.next();
  62.          if (SunJCE_b.b(var3.getProvider())) {
  63.             return new Mac(var3, var2, var0);
  64.          }
  65.       }
  66.  
  67.       throw new NoSuchAlgorithmException("Algorithm " + var0 + " not available");
  68.    }
  69.  
  70.    public static final Mac getInstance(String var0, String var1) throws NoSuchAlgorithmException, NoSuchProviderException {
  71.       GetInstance.Instance var2 = SunJCE_b.a("Mac", MacSpi.class, var0, var1);
  72.       return new Mac((MacSpi)var2.impl, var2.provider, var0);
  73.    }
  74.  
  75.    public static final Mac getInstance(String var0, Provider var1) throws NoSuchAlgorithmException {
  76.       GetInstance.Instance var2 = SunJCE_b.a("Mac", MacSpi.class, var0, var1);
  77.       return new Mac((MacSpi)var2.impl, var2.provider, var0);
  78.    }
  79.  
  80.    // $FF: renamed from: a () void
  81.    void method_0() {
  82.       if (this.field_2 == null && this.field_6 != null) {
  83.          synchronized(this.field_7) {
  84.             if (this.field_2 == null) {
  85.                if (field_0 != null) {
  86.                   int var2 = --field_8;
  87.                   if (var2 >= 0) {
  88.                      field_0.println("Mac.init() not first method called, disabling delayed provider selection");
  89.                      if (var2 == 0) {
  90.                         field_0.println("Further warnings of this type will be suppressed");
  91.                      }
  92.  
  93.                      (new Exception("Call trace")).printStackTrace();
  94.                   }
  95.                }
  96.  
  97.                NoSuchAlgorithmException var8 = null;
  98.  
  99.                while(this.field_5 != null || this.field_6.hasNext()) {
  100.                   Provider.Service var3;
  101.                   if (this.field_5 != null) {
  102.                      var3 = this.field_5;
  103.                      this.field_5 = null;
  104.                   } else {
  105.                      var3 = (Provider.Service)this.field_6.next();
  106.                   }
  107.  
  108.                   if (SunJCE_b.b(var3.getProvider())) {
  109.                      try {
  110.                         Object var4 = var3.newInstance((Object)null);
  111.                         if (var4 instanceof MacSpi) {
  112.                            this.field_2 = (MacSpi)var4;
  113.                            this.field_1 = var3.getProvider();
  114.                            this.field_5 = null;
  115.                            this.field_6 = null;
  116.                            return;
  117.                         }
  118.                      } catch (NoSuchAlgorithmException var6) {
  119.                         var8 = var6;
  120.                      }
  121.                   }
  122.                }
  123.  
  124.                ProviderException var9 = new ProviderException("Could not construct MacSpi instance");
  125.                if (var8 != null) {
  126.                   var9.initCause(var8);
  127.                }
  128.  
  129.                throw var9;
  130.             }
  131.          }
  132.       }
  133.    }
  134.  
  135.    // $FF: renamed from: a (java.security.Key, java.security.spec.AlgorithmParameterSpec) void
  136.    private void method_1(Key var1, AlgorithmParameterSpec var2) throws InvalidKeyException, InvalidAlgorithmParameterException {
  137.       synchronized(this.field_7) {
  138.          if (this.field_2 != null) {
  139.             this.field_2.engineInit(var1, var2);
  140.          } else {
  141.             Exception var4 = null;
  142.  
  143.             while(this.field_5 != null || this.field_6.hasNext()) {
  144.                Provider.Service var5;
  145.                if (this.field_5 != null) {
  146.                   var5 = this.field_5;
  147.                   this.field_5 = null;
  148.                } else {
  149.                   var5 = (Provider.Service)this.field_6.next();
  150.                }
  151.  
  152.                if (var5.supportsParameter(var1) && SunJCE_b.b(var5.getProvider())) {
  153.                   try {
  154.                      MacSpi var6 = (MacSpi)var5.newInstance((Object)null);
  155.                      var6.engineInit(var1, var2);
  156.                      this.field_1 = var5.getProvider();
  157.                      this.field_2 = var6;
  158.                      this.field_5 = null;
  159.                      this.field_6 = null;
  160.                      return;
  161.                   } catch (Exception var8) {
  162.                      if (var4 == null) {
  163.                         var4 = var8;
  164.                      }
  165.                   }
  166.                }
  167.             }
  168.  
  169.             if (var4 instanceof InvalidKeyException) {
  170.                throw (InvalidKeyException)var4;
  171.             } else if (var4 instanceof InvalidAlgorithmParameterException) {
  172.                throw (InvalidAlgorithmParameterException)var4;
  173.             } else if (var4 instanceof RuntimeException) {
  174.                throw (RuntimeException)var4;
  175.             } else {
  176.                String var10 = var1 != null ? var1.getClass().getName() : "(null)";
  177.                throw new InvalidKeyException("No installed provider supports this key: " + var10, var4);
  178.             }
  179.          }
  180.       }
  181.    }
  182.  
  183.    public final Provider getProvider() {
  184.       this.method_0();
  185.       return this.field_1;
  186.    }
  187.  
  188.    public final int getMacLength() {
  189.       this.method_0();
  190.       return this.field_2.engineGetMacLength();
  191.    }
  192.  
  193.    public final void init(Key var1) throws InvalidKeyException {
  194.       try {
  195.          if (this.field_2 != null) {
  196.             this.field_2.engineInit(var1, (AlgorithmParameterSpec)null);
  197.          } else {
  198.             this.method_1(var1, (AlgorithmParameterSpec)null);
  199.          }
  200.       } catch (InvalidAlgorithmParameterException var3) {
  201.          throw new InvalidKeyException("init() failed", var3);
  202.       }
  203.  
  204.       this.field_4 = true;
  205.    }
  206.  
  207.    public final void init(Key var1, AlgorithmParameterSpec var2) throws InvalidKeyException, InvalidAlgorithmParameterException {
  208.       if (this.field_2 != null) {
  209.          this.field_2.engineInit(var1, var2);
  210.       } else {
  211.          this.method_1(var1, var2);
  212.       }
  213.  
  214.       this.field_4 = true;
  215.    }
  216.  
  217.    public final void update(byte var1) throws IllegalStateException {
  218.       this.method_0();
  219.       if (!this.field_4) {
  220.          throw new IllegalStateException("MAC not initialized");
  221.       } else {
  222.          this.field_2.engineUpdate(var1);
  223.       }
  224.    }
  225.  
  226.    public final void update(byte[] var1) throws IllegalStateException {
  227.       this.method_0();
  228.       if (!this.field_4) {
  229.          throw new IllegalStateException("MAC not initialized");
  230.       } else {
  231.          if (var1 != null) {
  232.             this.field_2.engineUpdate(var1, 0, var1.length);
  233.          }
  234.  
  235.       }
  236.    }
  237.  
  238.    public final void update(byte[] var1, int var2, int var3) throws IllegalStateException {
  239.       this.method_0();
  240.       if (!this.field_4) {
  241.          throw new IllegalStateException("MAC not initialized");
  242.       } else {
  243.          if (var1 != null) {
  244.             if (var2 < 0 || var3 > var1.length - var2 || var3 < 0) {
  245.                throw new IllegalArgumentException("Bad arguments");
  246.             }
  247.  
  248.             this.field_2.engineUpdate(var1, var2, var3);
  249.          }
  250.  
  251.       }
  252.    }
  253.  
  254.    public final void update(ByteBuffer var1) {
  255.       this.method_0();
  256.       if (!this.field_4) {
  257.          throw new IllegalStateException("MAC not initialized");
  258.       } else if (var1 == null) {
  259.          throw new IllegalArgumentException("Buffer must not be null");
  260.       } else {
  261.          this.field_2.engineUpdate(var1);
  262.       }
  263.    }
  264.  
  265.    public final byte[] doFinal() throws IllegalStateException {
  266.       this.method_0();
  267.       if (!this.field_4) {
  268.          throw new IllegalStateException("MAC not initialized");
  269.       } else {
  270.          byte[] var1 = this.field_2.engineDoFinal();
  271.          this.field_2.engineReset();
  272.          return var1;
  273.       }
  274.    }
  275.  
  276.    public final void doFinal(byte[] var1, int var2) throws ShortBufferException, IllegalStateException {
  277.       this.method_0();
  278.       if (!this.field_4) {
  279.          throw new IllegalStateException("MAC not initialized");
  280.       } else {
  281.          int var3 = this.getMacLength();
  282.          if (var1 != null && var1.length - var2 >= var3) {
  283.             byte[] var4 = this.doFinal();
  284.             System.arraycopy(var4, 0, var1, var2, var3);
  285.          } else {
  286.             throw new ShortBufferException("Cannot store MAC in output buffer");
  287.          }
  288.       }
  289.    }
  290.  
  291.    public final byte[] doFinal(byte[] var1) throws IllegalStateException {
  292.       this.method_0();
  293.       if (!this.field_4) {
  294.          throw new IllegalStateException("MAC not initialized");
  295.       } else {
  296.          this.update(var1);
  297.          return this.doFinal();
  298.       }
  299.    }
  300.  
  301.    public final void reset() {
  302.       this.method_0();
  303.       this.field_2.engineReset();
  304.    }
  305.  
  306.    public final Object clone() throws CloneNotSupportedException {
  307.       this.method_0();
  308.       Mac var1 = (Mac)super.clone();
  309.       var1.field_2 = (MacSpi)this.field_2.clone();
  310.       return var1;
  311.    }
  312. }
  313.